/*
 * OptionPane.java  0.4.0 / Oct 26, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swing;

/**
 * Option Pane Component.
 *
 * @cute4j.native
 *    generate="header"
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public final class OptionPane extends Dialog {

// Public Static Fields. -------------------------------------------------------

  /**
   * <tt>Plain</tt> message type (the value is {@value}).
   */
  public static final int PLAIN_MESSAGE = -1;

  /**
   * <tt>Plain</tt> message type (the value is {@value}).
   */
  public static final int ERROR_MESSAGE = 0;

  /**
   * <tt>Information</tt> message type (the value is {@value}).
   */
  public static final int INFORMATION_MESSAGE = 1;

  /**
   * <tt>Warning</tt> message type (the value is {@value}).
   */
  public static final int WARNING_MESSAGE = 2;

  /**
   * <tt>Question</tt> message type (the value is {@value}).
   */
  public static final int QUESTION_MESSAGE = 3;

  /**
   * <tt>About</tt> message type (the value is {@value}).
   */
  public static final int ABOUT_MESSAGE = 4;

  /**
   * <tt>None</tt> option (the value is {@value}).
   */
  public static final int NONE_OPTION = 0x00000000;

  /**
   * <tt>Ok</tt> option (the value is {@value}).
   */
  public static final int OK_OPTION = 0x00000400;

  /**
   * <tt>Open</tt> option (the value is {@value}).
   */
  public static final int OPEN_OPTION = 0x00002000;

  /**
   * <tt>Save</tt> option (the value is {@value}).
   */
  public static final int SAVE_OPTION = 0x00000800;

  /**
   * <tt>Cancel</tt> option (the value is {@value}).
   */
  public static final int CANCEL_OPTION = 0x00400000;

  /**
   * <tt>Close</tt> option (the value is {@value}).
   */
  public static final int CLOSE_OPTION = 0x00200000;

  /**
   * <tt>Discard</tt> option (the value is {@value}).
   */
  public static final int DISCARD_OPTION = 0x00800000;

  /**
   * <tt>Apply</tt> option (the value is {@value}).
   */
  public static final int APPLY_OPTION = 0x02000000;

  /**
   * <tt>Reset</tt> option (the value is {@value}).
   */
  public static final int RESET_OPTION = 0x04000000;

  /**
   * <tt>None</tt> option (the value is {@value}).
   */
  public static final int RESTORE_DEFAULTS_OPTION = 0x08000000;

  /**
   * <tt>Help</tt> option (the value is {@value}).
   */
  public static final int HELP_OPTION = 0x01000000;

  /**
   * <tt>Save all</tt> option (the value is {@value}).
   */
  public static final int SAVE_ALL_OPTION = 0x00001000;

  /**
   * <tt>Yes</tt> option (the value is {@value}).
   */
  public static final int YES_OPTION = 0x00004000;

  /**
   * <tt>None</tt> option (the value is {@value}).
   */
  public static final int YES_TO_ALL_OPTION  = 0x00008000;

  /**
   * <tt>No</tt> option (the value is {@value}).
   */
  public static final int NO_OPTION = 0x00010000;

  /**
   * <tt>Not to all</tt> option (the value is {@value}).
   */
  public static final int NO_TO_ALL_OPTION = 0x00020000;

  /**
   * <tt>Abort</tt> option (the value is {@value}).
   */
  public static final int ABORT_OPTION = 0x00040000;

  /**
   * <tt>Retry</tt> option (the value is {@value}).
   */
  public static final int RETRY_OPTION = 0x00080000;

  /**
   * <tt>Ignore</tt> option (the value is {@value}).
   */
  public static final int IGNORE_OPTION = 0x00100000;

  /**
   * <tt>Yes and No</tt> options (the value is {@value}).
   */
  public static final int YES_NO_OPTIONS = YES_OPTION | NO_OPTION;

  /**
   * <tt>Yes, No and Cancel</tt> options (the value is {@value}).
   */
  public static final int YES_NO_CANCEL_OPTIONS = YES_OPTION | NO_OPTION |
                                                  CANCEL_OPTION;

  /**
   * <tt>Abort, Retry and Ignore</tt> options (the value is {@value}).
   */
  public static final int ABORT_RETRY_IGNORE_OPTIONS = ABORT_OPTION |
                                                       RETRY_OPTION |
                                                       IGNORE_OPTION;

// Package-Private Static Fields. ----------------------------------------------

  static final int OPTIONS_CHECK_MASK = ~(OK_OPTION | OPEN_OPTION |
                                          SAVE_OPTION | CANCEL_OPTION |
                                          CLOSE_OPTION | DISCARD_OPTION |
                                          APPLY_OPTION | RESET_OPTION |
                                          RESTORE_DEFAULTS_OPTION |
                                          HELP_OPTION | SAVE_ALL_OPTION |
                                          YES_OPTION | YES_TO_ALL_OPTION |
                                          NO_OPTION | NO_TO_ALL_OPTION |
                                          ABORT_OPTION | RETRY_OPTION |
                                          IGNORE_OPTION);

// Private Constructor. --------------------------------------------------------

 /**
  * Class has no instances.
  */
  private OptionPane() {
    // empty constructor body
  }

// Public Static Methods. ------------------------------------------------------

  /**
   * Displays message dialog.
   *
   * @param messageType the message type
   * @param parent the parent component
   * @param text the message text
   * @param title the dialog title
   * @param options the options
   * @param defaultOption the default option
   *
   * @return selected option
   */
  public static int showMessage(int messageType, Component parent,
                                String text, String title, int options,
                                int defaultOption) {
    Swing.disposedCheck();
    if ((options & OPTIONS_CHECK_MASK) != 0) {
      throw new IllegalArgumentException("Invalid options");
    }
    if ((defaultOption & OPTIONS_CHECK_MASK) != 0) {
      throw new IllegalArgumentException("Invalid default option");
    }
    if (parent != null) {
      return _showMessage(messageType, parent._delegate, text, title, options,
                          defaultOption);
    }
    return _showMessage(messageType, 0, text, title, options, defaultOption);
  }

  /**
   * Displays about message.
   *
   * @param parent the parent component
   * @param title the dialog title
   * @param message the message
   */
  public static void showAboutMessage(Component parent, String message,
                                      String title) {
    showMessage(ABOUT_MESSAGE, parent, message, title, OK_OPTION, NONE_OPTION);
  }

  /**
   * Displays information message.
   *
   * @param parent the parent component
   * @param title the dialog title
   * @param message the message
   *
   * @return selected option
   */
  public static int showInformationMessage(Component parent, String message,
                                           String title) {
    return showMessage(INFORMATION_MESSAGE, parent, message, title, OK_OPTION,
                       NONE_OPTION);
  }

  /**
   * Displays information message.
   *
   * @param parent the parent component
   * @param title the dialog title
   * @param message the message
   * @param options the options
   *
   * @return selected option
   */
  public static int showInformationMessage(Component parent, String message,
                                           String title, int options) {
    return showMessage(INFORMATION_MESSAGE, parent, message, title, options,
                       NONE_OPTION);
  }

  /**
   * Displays information message.
   *
   * @param parent the parent component
   * @param title the dialog title
   * @param message the message
   * @param options the options
   * @param defaultOption the default option
   *
   * @return selected option
   */
  public static int showInformationMessage(Component parent, String message,
                                           String title, int options,
                                           int defaultOption) {
    return showMessage(INFORMATION_MESSAGE, parent, message, title, options,
                       defaultOption);
  }

  /**
   * Displays question message.
   *
   * @param parent the parent component
   * @param title the dialog title
   * @param message the message
   *
   * @return selected option
   */
  public static int showQuestionMessage(Component parent, String message,
                                        String title) {
    return showMessage(QUESTION_MESSAGE, parent, message, title, OK_OPTION,
                       NONE_OPTION);
  }

  /**
   * Displays question message.
   *
   * @param parent the parent component
   * @param title the dialog title
   * @param message the message
   * @param options the options
   *
   * @return selected option
   */
  public static int showQuestionMessage(Component parent, String message,
                                        String title, int options) {
    return showMessage(QUESTION_MESSAGE, parent, message, title, options,
                       NONE_OPTION);
  }

  /**
   * Displays question message.
   *
   * @param parent the parent component
   * @param title the dialog title
   * @param message the message
   * @param options the options
   * @param defaultOption the default option
   *
   * @return selected option
   */
  public static int showQuestionMessage(Component parent, String message,
                                        String title, int options,
                                        int defaultOption) {
    return showMessage(QUESTION_MESSAGE, parent, message, title, options,
                       defaultOption);
  }

  /**
   * Displays warning message.
   *
   * @param parent the parent component
   * @param title the dialog title
   * @param message the message
   *
   * @return selected option
   */
  public static int showWarningMessage(Component parent, String message,
                                       String title) {
    return showMessage(WARNING_MESSAGE, parent, message, title, OK_OPTION,
                       NONE_OPTION);
  }

  /**
   * Displays warning message.
   *
   * @param parent the parent component
   * @param title the dialog title
   * @param message the message
   * @param options the options
   *
   * @return selected option
   */
  public static int showWarningMessage(Component parent, String message,
                                       String title, int options) {
    return showMessage(WARNING_MESSAGE, parent, message, title, options,
                       NONE_OPTION);
  }

  /**
   * Displays warning message.
   *
   * @param parent the parent component
   * @param title the dialog title
   * @param message the message
   * @param options the options
   * @param defaultOption the default option
   *
   * @return selected option
   */
  public static int showWarningMessage(Component parent, String message,
                                       String title, int options,
                                       int defaultOption) {
    return showMessage(WARNING_MESSAGE, parent, message, title, options,
                       defaultOption);
  }

  /**
   * Displays error message.
   *
   * @param parent the parent component
   * @param title the dialog title
   * @param message the message
   *
   * @return selected option
   */
  public static int showErrorMessage(Component parent, String message,
                                     String title) {
    return showMessage(ERROR_MESSAGE, parent, message, title, OK_OPTION,
                       NONE_OPTION);
  }

  /**
   * Displays error message.
   *
   * @param parent the parent component
   * @param title the dialog title
   * @param message the message
   * @param options the options
   *
   * @return selected option
   */
  public static int showErrorMessage(Component parent, String message,
                                     String title, int options) {
    return showMessage(ERROR_MESSAGE, parent, message, title, options,
                       NONE_OPTION);
  }

  /**
   * Displays error message.
   *
   * @param parent the parent component
   * @param title the dialog title
   * @param message the message
   * @param options the options
   * @param defaultOption the default option
   *
   * @return selected option
   */
  public static int showErrorMessage(Component parent, String message,
                                     String title, int options,
                                     int defaultOption) {
    return showMessage(ERROR_MESSAGE, parent, message, title, options,
                       defaultOption);
  }

// Package-Private Native Method. ----------------------------------------------

  static native int _showMessage(int messageType, long parentDelegate,
                                 String text, String title, int buttons,
                                 int defaultButton);

}
